	<div class="modal-dialog" role="document" style="width:800px;">
	    <div class="modal-content">
	        <div class="modal-header">
	            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	            <h4 class="modal-title" id="exampleModalLabel">设置空间管理员</h4>
	        </div>
	        <form class="form-horizontal" style="margin:4%;" id="houseForm">
	        	<input type="hidden" name="id" value="{$space.id}"/>
	        	<div class="form-group">
            		<label class="control-label col-sm-2">空间名称:</label>
                	<div class="col-sm-4" style="margin-top:6px;">
                		{$space.name}
                	</div>
            	</div>
            	<div class="form-group">
            		<label class="control-label col-sm-2">管理员:</label>
                	<div class="col-sm-4">
                		<select class="form-control" name="users" id="users">
							<option value="">请选择</option>
                			<foreach name="userList" item="user">
                				<option value="{$user.id}">{$user.real_name}</option>
                			</foreach>
                		</select>
                	</div>
            	</div>
            	<div id="userListDiv" class="form-group">
            		<label class="control-label col-sm-2">&nbsp;</label>
            		<foreach name="space.manager" item="user">
                    <button class="btn btn-primary" style="margin-right:5px;" type="button">
                        <span thisId="{$user.id}">&times;</span> {$user.real_name}
                    </button>
                    </foreach>
            	</div>
	        </form>
	        <div class="modal-footer">
	            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
	            <button type="button" id="save" class="btn btn-primary">保存</button>
	        </div>
	    </div>
	</div>
	
	<script type="text/javascript">
		var id = "{$space.id}";
		var userList = [];
		var removeAll = true;
		$(function(){
			init();
			$("#users").change(function(){
	            var checkUserId = parseInt($(this).val());
	            if(!common.inArray(checkUserId,userList)){
                    if(checkUserId && !isNaN(checkUserId)) {
                        userList.push(checkUserId);
                        addUserList(checkUserId,$(this).find("option:selected").text());
                    }
	            }
	        });
			$("#userListDiv").on('click','span',function(){
				userList.remove(parseInt($(this).attr("thisId")));
	            $(this).parent("button").remove();
	        });
			$("#save").bind("click",doSave);
		});
		
		function init(){
	        $("#userListDiv").find("span").each(function(k,item){
	        	removeAll = false;
	        	userList.push(parseInt($(item).attr("thisId")));
	        });
	    }
		
		function addUserList(id,name){
	        $("#userListDiv").append('<button class="btn btn-primary" style="margin-right:5px;" type="button">'+
	                        '<span thisId="'+id+'">&times;</span> '+name+
	                    '</button>');
	    }
		
		function doSave(){
			if(userList.length == 0){
				if(removeAll){
					common.alert("提示","请至少选择一个管理员!");
				}else{
					common.confirm("提示","确认删除该空间的所有管理员吗？",function(){
						doSetManager('');
		    		});
				}
			}else{
				doSetManager(userList.toString());
			}
		}
		
		function doSetManager(userId){
			common.ajax("{:U('Admin/Space/Spaces/doSetManager')}",{userId:userId,id:id},function(data){
                if(data.status){
                    common.alert("提示","空间管理员设置成功!",function(){
                        common.reload();
                    });
                }
            });
		}
	</script>